#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
struct Node {
  int val, c, l, r;
  int pre, sum;
} a[N];

void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i].val >> a[i].c >> a[i].l >> a[i].r;
  map<pii, int> pre;
  int ans = 0;
  rep(i, 1, n) {
    if (a[i].l) {
      int x = a[i].l, y = a[i].r + a[i].c;
      int j = a[i].pre = pre[pii(x, y)];
      if (j) a[i].sum = a[i].val + a[j].sum;
    } else {
      a[i].sum = a[i].val;
    }
    if (a[i].pre || !a[i].l) {
      int x = a[i].l + a[i].c, y = a[i].r;
      int j = pre[pii(x, y)];
      if (!j || a[j].sum < a[i].sum) pre[pii(x, y)] = i;
    }
    if (!a[i].r)
      if (a[ans].sum < a[i].sum) ans = i;
  }
  if (!ans)
    cout << 0;
  else {
    vector<int> res;
    int x = ans;
    while (x) {
      res.push_back(x);
      x = a[x].pre;
    }
    reverse(res.begin(), res.end());
    cout << res.size() << endl;
    for (int x : res) cout << x << ' ';
  }
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}